<?php
require_once('../../controller/auth.php');
//Start session
	session_start();
	
	//Include database connection details
	require_once('../inc/config.inc');
	
	
	
	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	
	$status=$_POST['stat'];
	
	
	mysql_query ('SET NAMES utf8');
	mysql_query('SET CHARACTER_SET utf8');
	switch($status){
	case 0 :$query = "SELECT * FROM `main` WHERE `status`=0";
			$stat = "Initiated";
			$progress="<div class='bar' style='width: 10%;' rel='tooltip' title='The overall progress of project is 10%!' data-placement='top'></div>";
			break;
	case 1 :$query = "SELECT * FROM `main` WHERE `status`=1";
			$stat = "Approved By TED";
			$progress="<div class='bar' style='width: 30%;' rel='tooltip' title='The overall progress of project is 10%!' data-placement='top'></div>";
			break;
	case 2 :$query = "SELECT * FROM `main` WHERE `status`=2";
			$stat = "Budget Allocated";
			$progress="<div class='bar' style='width: 50%;' rel='tooltip' title='The overall progress of project is 10%!' data-placement='top'></div>";
			break;
	case 3 :$query = "SELECT * FROM `main` WHERE `status`=3";
			$stat = "Allotment Received";
			$progress="<div class='bar' style='width: 80%;' rel='tooltip' title='The overall progress of project is 10%!' data-placement='top'></div>";
			break;
	case 4 :$query = "SELECT * FROM `main` WHERE `status`=4";
			$stat = "Done";
			$progress="<div class='bar' style='width: 100%;' rel='tooltip' title='The overall progress of project is 10%!' data-placement='top'></div>";
			break;
			default:$query = "SELECT * FROM `main`";
	
	}
	
	$result=mysql_query($query);
	//Status=0 means : initiated, 1 means: Approved by MoE, 2 means: Budged Allocated, 3 mean: Allotment Received, 4 means: Done
	if($result){
	echo "<table class='table table-bordered'>";
	echo "<tr><th>Serial Number</th><th>Project Name</th><th>Request Number</th><th>Status</th><th>Overall Progress&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th><th colspan='2' style='text-align:center'><i class='icon-cog'></i>&nbsp;Actions</th></tr>";
	$counter = 1;	
	while($row_pro=mysql_fetch_array($result)){
		
		echo "<tr>";
		echo "<td>" . $counter . "</td><td>" . $row_pro['proj_name'] . "</td><td>" . $row_pro['request_no'] . "</td><td>" . $stat . "</td><td><div class='progress progress-striped'>" . $progress . "</div></td><td style='text-align:center'><a href='details.php?id=$row_pro[serial]'><i class='icon-eye-open'></i>&nbsp;Details</a></td><td style='text-align:center'><a href='update.php?id=$row_pro[serial]'><i class='icon-edit'></i>&nbsp;Update</a></td>";
		echo "</tr>";
		$counter++;
	
	}
	
	}
	else {
	echo "Some Problems Exists : ".mysql_error();;
		
		}
		?>